<!DOCTYPE html>

<html lang="zh-CN">
<head>
<meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <title>管脚控制器</title>
 <style>
     body {
         display: flex;
         justify-content: center;
         align-items: center;
         font-family: Arial, sans-serif;
     }
     input[type="number"] {
         width: 100%;
         padding: 10px;
         margin-bottom: 10px;
     }
     button {
         width: 100%;
         padding: 10px;
         margin-bottom: 10px;
     }
 </style>
</head>
<body>
    <div class="controls">
        <label for="pin-num">管脚号</label>
        <input id="pin-num" type="number" name="number" value="1"/>
        <button onclick="setHIGH()" id="high-button">上拉</button>
        <button onclick="setLOW()"  id="low-button">下拉</button>
    </div>

 <script>
    function setHIGH() {
            const inputTerminal = document.getElementById('pin-num');
            const text = inputTerminal.value;
            if (text) {
                sendAjax(":" + text + " 1");
            }
        }
    function setLOW() {
            const inputTerminal = document.getElementById('pin-num');
            const text = inputTerminal.value;
            if (text) {
                sendAjax(":" + text + " 0");
            }
        }
    function sendAjax(text) {
        fetch('pin_set', {
            method: 'POST',
            headers: {
                'Content-Type': 'text/plain'
            },
            body: text
        })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.text();
            })
            .then(data => {
                console.log('Success:', data);

            })
            .catch((error) => {
                console.error('Error:', error);
            });
        }
 </script>
</body>
</html>